function validate()
{
    if (tblUpload.style.display != "none" && Attachments.userFile.value != "")
    {
        alert(LOCID_FILE_DID_NOT_ATTACH);
        return false;
    }
    else
    {
        return true;
    }
}
function remove(iType, sGuid)
{
    if (confirm(LOCID_REMOVE_ATTACHMENT_ALRT))
    {
        var command = new RemoteCommand("Annotation", "RemoveAttachment");
        command.SetParameter("id", sGuid);
        command.SetParameter("type", iType);
        var result = command.Execute();

        if (result.Success)
        {
            tblFile.style.display = "none";
            tblUpload.style.display = "inline";
            alert(LOCID_ALERT_REMOVED_ATTACHMENT);

            if (iType == ActivityMimeAttachment)
            {
                with(Attachments)
                {
                    SuccessURL.value = SetQueryString(SuccessURL.value, "id", "");
                    AttachmentId.value = "";
                }
            }

            try{window.opener.auto(crmFormSubmit.crmFormSubmitObjectType.value);}catch(e){}
            if (Attachments.CloseWindow.value == "True")
            {
                window.close();
            }
        }
    }
}
function attach(sUrl, sNode)
{
    var sFileName = Attachments.userFile.value;
    if (sFileName == "")
    {
        alert(LOCID_ALERT_SEPECIFY_FILE);
        return false;
    }
    sFileName = sFileName.slice(sFileName.lastIndexOf("\\") + 1);
    if (sFileName.length > 185)
    {
        alert(LOCID_ATTACHMENT_NAME_LENGTH);
        return false;
    }
    var bIsValid = false;

    if (Attachments.AttachmentId.value == "")
    {
        if (!IsNull(crmForm.subject) && (crmForm.subject.value === ""))
        {
            crmForm.subject.DataValue = LOCID_NOTES_FILE_ATTACHMENT;
        }
        bIsValid = (crmForm.BuildXml(true) !=  2);
    }
    else
    {
        bIsValid = (crmForm.BuildXml(true, true) !=  2);
    }
    if (bIsValid)
    {
        try
        {
            if(bWorkflowStep)
            {
                BuildWorkflowNoteXml();
            }
        }
        catch (ex)
        {
        }
        Attachments.crmFormSubmitXml.value = crmFormSubmit.crmFormSubmitXml.value;
        crmForm._bSaving = true;

        Attachments.SuccessURL.value = SetQueryString(Attachments.SuccessURL.value, "rg", "1");
        Attachments.SuccessURL.value = SetQueryString(Attachments.SuccessURL.value, "cw", Attachments.CloseWindow.value);
        if (location.href.indexOf("hideDesc=1") != -1)
        {
            Attachments.SuccessURL.value = SetQueryString(Attachments.SuccessURL.value, "hideDesc", "1");
        }
        try
        {
            Attachments.submit();

            var parentPage = window.opener;
            if (!IsNull(parentPage) && (typeof(parentPage.OnAttach) == "function" || typeof(parentPage.OnAttach) == "object"))
            {
                parentPage.OnAttach();
            }
        }
        catch (e)
        {
            alert(LOCID_FILE_DOES_NOT_EXISTS);
            return false;
        }
    }
}
function attachmentClose()
{
    var msg =  LOCID_FORMS_SAVE_CONFIRM_TITLE ;
    if (crmForm._bSaving)
    {
        return;
    }
    if (crmForm.BuildXml(false, true) != 3)
    {
        event.returnValue = msg;
    }
    else if (tblUpload.style.display != "none" && Attachments.userFile.value != "")
    {
        event.returnValue = msg;
    }
}
function getTypeFromURL(sUrl)
{
    sUrl = sUrl.toLowerCase();
    if (sUrl.indexOf("note") != -1) return Annotation;
    if (sUrl.indexOf("activities") != -1) return ActivityMimeAttachment;
    if (sUrl.indexOf("saleslit") != -1) return SalesLiteratureItem;
}
